home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
-
- File: DialogUtils.h
-
- Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
-
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- *************************************************************************************/
-
- #ifndef __DIALOGUTILS__
- #define __DIALOGUTILS__
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __MACTYPES__
- #include <MacTypes.h>
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef __QDOFFSCREEN__
- #include <QDOffscreen.h>
- #endif
-
- #ifndef __PALETTES__
- #include <Palettes.h>
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- /***** TYPES ***********************************************************************************************/
- #pragma mark Types
-
- //typedef SInt16 DialogItem;
- /*typedef SInt16 DialogItemType;*/ // this definition is in the new Universal Headers
- typedef SInt16 ControlValue;
-
- /***** ENUMS ***********************************************************************************************/
- typedef enum { kGSActive = true, kGSInactive = false } GScActiveType;
-
- typedef enum
- {
- GScRampW = 0, // 0xffff
- GScRamp1 = 1, // 0xeeee
- GScRamp2 = 2, // 0xddd (background color of dialog)
- GScRamp3 = 3, // 0xcccc
- GScRamp4 = 4, // 0xbbbb
- GScRamp5 = 5, // 0xaaaa
- GScRamp6 = 6, // 0x9999
- GScRamp7 = 7, // 0x8888
- GScRamp8 = 8, // 0x7777
- GScRamp9 = 9, // 0x6666
- GScRamp10 = 10, // 0x5555
- GScRamp11 = 11, // 0x4444
- GScRamp12 = 12, // 0x3333
- GScRampA1 = 13, // 0x2222
- GScRampA2 = 14, // 0x1111
- GScRampB = 15, // 0x0000
-
- GScRampWhite = GScRampW,
- GScRampBlack = GScRampB,
- GScRampBG = GScRamp2 // this should be the background color of the dialog
- } GScGrayRamp;
-
- /***** C Functions ***********************************************************************************************/
- #pragma mark C Functions
-
- void DialogItem_SetUserProc(DialogRef inDialog, DialogItemIndex inItem, const UserItemUPP inUserProc);
- void DialogItem_SetOKUserProc(DialogRef inDialog, DialogItemIndex inItem);
- void DialogItem_SetPrimaryGroupUserProc(DialogRef inDialog, DialogItemIndex inItem);
- void DialogItem_SetSecondaryGroupUserProc(DialogRef inDialog, DialogItemIndex inItem);
-
- ControlHandle DialogItem_GetControl(DialogRef inDialog, DialogItemIndex inItem);
- void DialogItem_HiliteControl(DialogRef inDialog, DialogItemIndex inItem, ControlPartCode hiliteState);
- void DialogItem_AnimateButtonClick(DialogRef inDialog, DialogItemIndex inItem);
-
- // popup menu helper routines
- MenuHandle DialogItem_GetPopupMenu(DialogRef inDialog, DialogItemIndex inItem);
- void DialogItem_SetPopupMenu(DialogRef inDialog, DialogItemIndex inItem, MenuHandle inMenuHandle);
-
- // enable/disable dialog item
- void DialogItem_Enable(DialogRef inDialog, DialogItemIndex inItem);
- void DialogItem_Disable(DialogRef inDialog, DialogItemIndex inItem);
-
- // get/set text
- void DialogItem_GetText(DialogRef inDialog, DialogItemIndex inItem, Str255 outText);
- void DialogItem_SetText(DialogRef inDialog, DialogItemIndex inItem, const StringPtr inText);
- void DialogItem_SetTextQuietly(DialogRef inDialog, DialogItemIndex inItem, const StringPtr inText);
-
- // radio button functions
- void DialogItem_SetRadioButtonGroup(DialogRef inDialog, DialogItemIndex inFirstItem, DialogItemIndex inLastItem, DialogItemIndex inNewItem);
- DialogItemIndex DialogItem_GetRadioButtonGroup(DialogRef inDialog, DialogItemIndex inFirstItem, DialogItemIndex inLastItem);
-
- // min,max and value get and set routines
- ControlValue DialogItem_GetValue(DialogRef inDialog, DialogItemIndex inItem);
- ControlValue DialogItem_GetMin(DialogRef inDialog, DialogItemIndex inItem);
- ControlValue DialogItem_GetMax(DialogRef inDialog, DialogItemIndex inItem);
-
- void DialogItem_SetValue(DialogRef inDialog, DialogItemIndex inItem, ControlValue value);
- void DialogItem_SetMin(DialogRef inDialog, DialogItemIndex inItem, ControlValue min);
- void DialogItem_SetMax(DialogRef inDialog, DialogItemIndex inItem, ControlValue max);
-
- void DialogItem_SetValueQuietly(DialogRef inDialog, DialogItemIndex inItem, ControlValue value);
-
- // get,set item rectangle
- void DialogItem_GetRect(DialogRef inDialog, DialogItemIndex inItem, Rect *outItemRect);
- void DialogItem_SetRect(DialogRef inDialog, DialogItemIndex inItem, const Rect *inItemRect);
-
- void DialogItem_DeltaRect(DialogRef inDialog, DialogItemIndex inItem, short inDeltaTop, short inDeltaLeft, short inDeltaBottom, short inDeltaRight);
- void DialogItem_OffsetRect(DialogRef inDialog, DialogItemIndex inItem, short inDeltaH, short inDeltaV);
- short DialogItem_GetWidth(DialogRef inDialog, DialogItemIndex inItem);
-
- // validate/invalidate (i.e. updates/drawing)
- void DialogItem_Invalidate(DialogRef inDialog, DialogItemIndex inItem);
- void DialogItem_Valididate(DialogRef inDialog, DialogItemIndex inItem);
-
- // show/hide
- void DialogItem_Show(DialogRef inDialog, DialogItemIndex inItem);
- void DialogItem_Hide(DialogRef inDialog, DialogItemIndex inItem);
-
- // getting and setting the type
- DialogItemType DialogItem_GetType(DialogRef inDialog, DialogItemIndex inItem);
- void DialogItem_SetType(DialogRef inDialog, DialogItemIndex inItem, DialogItemType inType);
-
- // getting and setting the default item
- DialogItemIndex Dialog_GetDefaultItem(DialogRef inDialog);
- DialogItemIndex Dialog_GetCancelItem(DialogRef inDialog);
-
- void Dialog_SetDefaultItem(DialogRef inDialog, DialogItemIndex inItem);
- void Dialog_SetCancelItem(DialogRef inDialog, DialogItemIndex inItem);
- void Dialog_SetTracksCursor(DialogRef inDialog, Boolean tracks);
-
- /**** validates/invalidates the whole window ****/
- void Window_Invalidate(WindowRef inWindow);
- void Window_Validate(WindowRef inWindow);
-
- /**** FilterKeyEvent (ok/cancel fitering for keyDown events) (set default/cancel item first) */
- Boolean FilterKeyEvent(DialogPtr inDialog, EventRecord *inEvent, DialogItemIndex *outItem);
-
- /**** KeyEventOK and KeyEventCancel */
- Boolean KeyEventOK(EventRecord *inEvent);
- Boolean KeyEventCancel(EventRecord *inEvent);
-
- /**** Modern Standard FilterProc (ok/cancel hiliting/enabling & accepts ok/cancel key presses) */
- extern ModalFilterUPP ModernStdFilterProcUPP;
- pascal Boolean ModernStdFilterProc(DialogPtr inDialog, EventRecord *inEvent, DialogItemIndex *outItem);
-
- /**** GetKeyModifiers returns current modifier state */
- EventModifiers GetKeyModifiers(void);
-
- /**** Simplified CopyBits functions (no more port or color concerns) */
- void CopyBitsLite(CGrafPtr src, CGrafPtr dst, const Rect *srcRect, const Rect *dstRect);
- void CopyBitsLiteWithColor(CGrafPtr src, CGrafPtr dst, const Rect *srcRect, const Rect *dstRect, const RGBColor *inColor);
-
- /**** Grayscale Functions */
- void GScForeColor_Set(GScGrayRamp color);
- void GScBackColor_Set(GScGrayRamp color);
-
- void GScTopLeft_Draw(const Rect *r, GScGrayRamp color); // draws the top left of a rect w/o corners
- void GScBotRight_Draw(const Rect *r, GScGrayRamp color); // draws the bot right of a rec w/o corners
-
- void GScGroupBox_PrimarySimple_Draw(const Rect *r, GScActiveType active);
- void GScGroupBox_SecondarySimple_Draw(const Rect *r, GScActiveType active);
-
- void GScGroupBox_PrimaryNamed_Draw(const Rect *r, const Str255 string, GScActiveType active);
- void GScGroupBox_SecondaryNamed_Draw(const Rect *r, const Str255 string, GScActiveType active);
-
- void GScTextEntryFrame_Draw(const Rect *r, GScActiveType active);
-
- #ifdef __cplusplus
- }
- #endif
-
-
- #pragma mark C++ Functions
-
- #ifdef __cplusplus
- class QDColorState
- {
- public:
- QDColorState();
- ~QDColorState();
-
- static void Clear();
-
- private:
- ColorSpec mForegroundColor;
- ColorSpec mBackgroundColor;
- };
-
- class QDTextState
- {
- public:
- QDTextState();
- ~QDTextState();
-
- static void Clear();
-
- private:
- SInt16 mFontID;
- SInt16 mFace;
- SInt16 mMode;
- SInt16 mSize;
- };
-
- class QDPenState
- {
- public:
- QDPenState();
- ~QDPenState();
-
- static void Clear();
-
- private:
- PenState mPenState;
- };
-
- class GWorldState
- {
- public:
- GWorldState(void);
- GWorldState(GrafPtr inNewPort); // sets the port to inNewPort
-
- ~GWorldState(void);
-
- private:
- CGrafPtr mPort;
- GDHandle mGDH;
- };
- #endif /* __cplusplus */
-
-
- /*
- *
- * Stackbased classes for saving/restoring graphics
- *
- */
-
- /***** MACROS ***********************************************************************************************/
- #pragma mark Macros
-
- #ifdef __cplusplus
- // QuickDraw shortcut
- inline Boolean isColorPort(GrafPtr p) { return ((((GrafPtr)p)->portBits.rowBytes & 0xC000) == 0xC000); }
-
- // WindowManager shortcut
- inline Boolean isDialogWindow(WindowRef w) { return (kDialogWindowKind == GetWindowKind(w)); }
-
- // DialogManager type shortcuts
- inline Boolean isUserType(DialogItemType t) { return ((t & ~kItemDisableBit) == userItem); }
-
- inline Boolean isControlType(DialogItemType t) { return ((t & kControlDialogItem) == kControlDialogItem); }
- inline Boolean isButtonType(DialogItemType t) { return ((t & ~kItemDisableBit) == kButtonDialogItem); }
- inline Boolean isCheckBoxType(DialogItemType t) { return ((t & ~kItemDisableBit) == kCheckBoxDialogItem); }
- inline Boolean isRadioButtonType(DialogItemType t) { return ((t & ~kItemDisableBit) == kRadioButtonDialogItem); }
- inline Boolean isResourceControlType(DialogItemType t) { return ((t & ~kItemDisableBit) == kResourceControlDialogItem); }
-
- inline Boolean isStaticTextType(DialogItemType t) { return ((t & ~kItemDisableBit) == kStaticTextDialogItem); }
- inline Boolean isEditTextType(DialogItemType t) { return ((t & ~kItemDisableBit) == kEditTextDialogItem); }
-
- inline Boolean isIconType(DialogItemType t) { return ((t & kIconDialogItem) == kIconDialogItem); }
- inline Boolean isPictureType(DialogItemType t) { return ((t & kPictureDialogItem) == kPictureDialogItem); }
-
- inline Boolean isDisabledType(DialogItemType t) { return ((t & kItemDisableBit) == kItemDisableBit); }
- inline Boolean isEnabledType(DialogItemType t) { return ((t & kItemDisableBit) == 0); }
- #else
- // QuickDraw shortcut
- #define isColorPort(p) ((((GrafPtr)p)->portBits.rowBytes & 0xC000) == 0xC000)
-
- // window manager shortcut
- #define isDialogWindow(w) (kDialogWindowKind == GetWindowKind(w))
-
- // type shortcuts
- #define isUserType(t) ((t & ~kItemDisableBit) == userItem)
-
- #define isControlType(t) ((t & kControlDialogItem) == kControlDialogItem)
- #define isButtonType(t) ((t & ~kItemDisableBit) == kButtonDialogItem)
- #define isCheckBoxType(t) ((t & ~kItemDisableBit) == kCheckBoxDialogItem)
- #define isRadioButtonType(t) ((t & ~kItemDisableBit) == kRadioButtonDialogItem)
- #define isResourceControlType(t) ((t & ~kItemDisableBit) == kResourceControlDialogItem)
-
- #define isStaticTextType(t) ((t & ~kItemDisableBit) == kStaticTextDialogItem)
- #define isEditTextType(t) ((t & ~kItemDisableBit) == kEditTextDialogItem)
-
- #define isIconType(t) ((t & kIconDialogItem) == kIconDialogItem)
- #define isPictureType(t) ((t & kPictureDialogItem) == kPictureDialogItem)
-
- #define isDisabledType(t) ((t & kItemDisableBit) == kItemDisableBit)
- #define isEnabledType(t) ((t & kItemDisableBit) == 0)
- #endif
-
- #endif __ISPDIALOGUTILS__
-